package com.hushan.elevator.dao;

import com.hushan.elevator.model.UserRole;
import com.hushan.elevator.model.UserRolePK;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRoleRepository  extends JpaRepository<UserRole, UserRolePK> {
    @Modifying
    @Transactional
    @Query(value = "UPDATE auth_user_role " +
            "SET role_id = :newRoleId " +
            "WHERE user_id = :userId AND role_id = :roleId;",nativeQuery = true)
    void updateUserRole(Integer userId, Integer roleId, Integer newRoleId);
}
